import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class JanelaPrincipal extends JFrame implements ActionListener{

        private static JanelaPrincipal janela;
        
        static public JanelaPrincipal GetInstance(){
                if (janela == null) janela = new JanelaPrincipal();
                return janela;
        }
        
        public void TrocaPainel(JPanel painel){
                JanelaPrincipal.GetInstance().remove(JanelaPrincipal.GetInstance().getContentPane());
                JanelaPrincipal.GetInstance().setContentPane(painel);
                JanelaPrincipal.GetInstance().setVisible(true);
                
        }
                
        private JanelaPrincipal(){
                // cria barra de menu
                JMenuBar menuBar = new JMenuBar();  
                
                // criar menu cadastro
                JMenu mCadastro = new JMenu("Cadastro");
                
                JMenu mBD = new JMenu("Banco de Dados");
                
                // sub-itens do menu cadastro
                JMenuItem mInserir = new JMenuItem("Inserir");  
                mInserir.addActionListener(new ActionListener() {
                        
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                JanelaPrincipal.GetInstance().TrocaPainel(new JanelaInserir());
                                // TODO Auto-generated method stub
                                
                        }
                });
                
                mCadastro.add(mInserir);
                
                
                
                
                JMenuItem mRemover = new JMenuItem("Remover");
                mRemover.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        JanelaPrincipal.GetInstance().TrocaPainel(new JanelaRemover());
                    }
                });
                mCadastro.add(mRemover);                
                
                JMenuItem mAtualizar = new JMenuItem("Atualizar");
                // ao clicar em Atualizar ir para  JanelaUpdate
                mAtualizar.addActionListener( new ActionListener() {
                        
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                //JanelaPrincipal.GetInstance().TrocaPainel(new JanelaUpdate());
                                // TODO Auto-generated method stub
                                
                        }
                });
                mCadastro.add(mAtualizar);
                
                JMenuItem mPesquisar = new JMenuItem("Pesquisar");
                mPesquisar.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                JanelaPrincipal.GetInstance().TrocaPainel(new JanelaPesquisar());
                        }
                });
                mCadastro.add(mPesquisar);
                
                menuBar.add(mCadastro);
                

                JMenuItem mListar = new JMenuItem("Listar");  
                mListar.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                JanelaPrincipal.GetInstance().TrocaPainel(new JanelaListar());
                        }
                });
                mBD.add(mListar);
                menuBar.add(mBD);
                
                this.setJMenuBar(menuBar);
                
                //Dimension tamanho_min = new Dimension(578, 384);
                Dimension tamanho_min = new Dimension(898, 576);
                Dimension tamanho_max = new Dimension(898, 576); // dimensoes da imagem de fundo
                this.setTitle("CRUD Empresario Junior");
                this.add(new JLabel ("CRUD Empresario Junior"));
                this.setMinimumSize(tamanho_min); // ALTEREI AQUI
                this.setMaximumSize(tamanho_max);
                this.pack();
                this.setVisible(true);
                this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                
        }
        
        /**
         * @param args
         */
        public static void main(String[] args) {
                
                
                JanelaPrincipal.GetInstance().TrocaPainel(new JanelaInicial());
        
                // TODO Auto-generated method stub

        }

        @Override
        public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                
        }

}
